<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="专案名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入专案名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专案代码" prop="projectCode">
        <el-input
          v-model="queryParams.projectCode"
          placeholder="请输入专案代码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['info:supplierMgmt:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['info:supplierMgmt:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['info:supplierMgmt:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['info:supplierMgmt:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="supplierMgmtList" @selection-change="handleSelectionChange">
      <el-table-column type="selection"  width="55" align="center" />
      <el-table-column label="序号" align="center" prop="sqeId" sortable />
      <el-table-column label="上传FTP账号" show-overflow-tooltip align="center" prop="upFtpAccount" />
      <el-table-column label="审核人账号" show-overflow-tooltip align="center" prop="auditorAccount" />
      <el-table-column label="厂商FTP账号" show-overflow-tooltip align="center" prop="vendorFtpAccount" />
      <el-table-column label="上传FTP文件夹" show-overflow-tooltip align="center" prop="upFtpFolderIct" />
      <el-table-column label="审核人文件夹" show-overflow-tooltip align="center" prop="auditorFolder" />
      <el-table-column label="厂商文件夹权限" show-overflow-tooltip align="center" prop="vendorFolderPermissions" />
      <el-table-column label="ICT上传文件夹权限" show-overflow-tooltip align="center" prop="ictUpFolderPermissions" />
      <el-table-column label="审核人文件夹权限" show-overflow-tooltip align="center" prop="auditorFolderPermissions" />
      <el-table-column label="厂商FTP账号有效期" show-overflow-tooltip align="center" prop="vendorFtpAccountIndate" width="180" sortable >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.vendorFtpAccountIndate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['info:supplierMgmt:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['info:supplierMgmt:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改供应商管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body center>
      <el-form ref="form" :model="form" :rules="rules" label-width="150px">
        <el-row>
          <el-col :span="11">
            <el-form-item label="上传FTP账号" prop="upFtpAccount">
              <el-input v-model="form.upFtpAccount" placeholder="请输入上传FTP账号" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="审核人账号" prop="auditorAccount">
              <el-input v-model="form.auditorAccount" placeholder="请输入审核人账号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="厂商FTP账号" prop="vendorFtpAccount">
              <el-input v-model="form.vendorFtpAccount" placeholder="请输入厂商FTP账号" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="上传FTP文件夹" prop="upFtpFolderIct">
              <el-input v-model="form.upFtpFolderIct" placeholder="请输入上传FTP文件夹" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
            <el-form-item label="审核人文件夹" prop="auditorFolder">
              <el-input v-model="form.auditorFolder" placeholder="请输入审核人文件夹" />
            </el-form-item>
          </el-col>
          <el-col :span="11">
            <el-form-item label="厂商FTP账号有效期" prop="vendorFtpAccountIndate">
              <el-date-picker clearable size="small"
                              v-model="form.vendorFtpAccountIndate"
                              type="date"
                              value-format="yyyy-MM-dd"
                              placeholder="选择厂商FTP账号有效期"
                              :style="{width: '99.5%'}"
                              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="11">
        <el-form-item label="专案名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入专案名称" />
        </el-form-item>
        </el-col>
          <el-col :span="11">
        <el-form-item label="专案代码" prop="projectCode">
          <el-input v-model="form.projectCode" placeholder="请输入专案代码" />
        </el-form-item>
        </el-col>
        </el-row>
        <el-form-item label="厂商文件夹权限" prop="vendorFolderPermissions">
          <el-checkbox-group v-model="form.vendorFolderPermissions" size="medium" >
            <el-checkbox label="无权限" :disabled="zios" @change="change"></el-checkbox>
            <el-checkbox label="上传" :disabled="boo"  @change="changes"></el-checkbox>
            <el-checkbox label="下载" :disabled="boo" @change="changea"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="ICT上传文件夹权限" prop="ictUpFolderPermissions">
          <el-checkbox-group v-model="form.ictUpFolderPermissions" size="medium">
            <el-checkbox label="无权限" :disabled="zios1" @change="change1"></el-checkbox>
            <el-checkbox label="上传" :disabled="boo1" @change="changes1"></el-checkbox>
            <el-checkbox label="下载" :disabled="boo1" @change="changesb"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <el-form-item label="审核人文件夹权限" prop="auditorFolderPermissions">
          <el-checkbox-group v-model="form.auditorFolderPermissions" size="medium">
            <el-checkbox label="无权限" :disabled="zios2" @change="change2"></el-checkbox>
            <el-checkbox label="上传" :disabled="boo2" @change="changes2"></el-checkbox>
            <el-checkbox label="下载" :disabled="boo2" @change="changesc"></el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        

        
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listSupplierMgmt, getSupplierMgmt, delSupplierMgmt, addSupplierMgmt, updateSupplierMgmt, exportSupplierMgmt } from "@/api/info/supplierMgmt";

  export default {
    name: "SupplierMgmt",
    data() {
      return {
        a: '',
        b: '',
        c: '',
        d: '',
        e: '',
        f: '',
        zios: false,
        zios1: false,
        zios2: false,
        boo: false,
        boo1: false,
        boo2: false,
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 供应商管理表格数据
        supplierMgmtList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          upFtpAccount: null,
          auditorAccount: null,
          vendorFtpAccount: null,
          upFtpFolderIct: null,
          auditorFolder: null,
          vendorFolderPermissions: null,
          ictUpFolderPermissions: null,
          auditorFolderPermissions: null,
          vendorFtpAccountIndate: null,
          updateName: null,
          createName: null,
          reserved: null,
          projectName: null,
          projectCode: null
        },
        //表单参数
        formData:{
          vendorFolderPermissions: [],

          ictUpFolderPermissions: [],

          auditorFolderPermissions: [],

        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          upFtpAccount: [
            {required: true, message: "上传FTP账号不能为空", trigger: "blur"}
          ],
          auditorAccount: [
            {required: true, message: "审核人账号不能为空", trigger: "blur"}
          ],
          vendorFtpAccount: [
            {required: true, message: "厂商FTP账号不能为空", trigger: "blur"}
          ],
          upFtpFolderIct: [
            {required: true, message: "上传FTP文件夹不能为空", trigger: "blur"}
          ],
          auditorFolder: [
            {required: true, message: "审核人文件夹不能为空", trigger: "blur"}
          ],
          vendorFtpAccountIndate: [
            {required: true, message: "厂商FTP账号有效期不能为空", trigger: "blur"}
          ],
          projectName: [
            {required: true, message: "专案名称不能为空", trigger: "blur"}
          ],
          projectCode: [
            {required: true, message: "专案代码不能为空", trigger: "blur"}
          ],
          vendorFolderPermissions: [
            {required: true, message: "厂商文件夹权限不能为空", trigger: "blur"}
          ],
          ictUpFolderPermissions: [
            {required: true, message: "ICT上传文件夹权限不能为空", trigger: "blur"}
          ],
          auditorFolderPermissions: [
            {required: true, message: "审核人文件夹权限不能为空", trigger: "blur"}
          ],
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询供应商管理列表 */
      getList() {
        this.loading = true;
        listSupplierMgmt(this.queryParams).then(response => {
          this.supplierMgmtList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          sqeId: null,
          upFtpAccount: null,
          auditorAccount: null,
          vendorFtpAccount: null,
          upFtpFolderIct: null,
          auditorFolder: null,
          vendorFolderPermissions: [],
          ictUpFolderPermissions: [],
          auditorFolderPermissions: [],
          vendorFtpAccountIndate: null,
          updateName: null,
          updateTime: null,
          createName: null,
          createTime: null,
          reserved: null,
          projectName: null,
          projectCode: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.sqeId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      change(val){
        if(val == true){
          this.boo = true
        }else if(val == false){
          this.boo = false
        }
      },
      change1(val){
        if(val == true){
          this.boo1 = true
        }else if(val == false){
          this.boo1 = false
        }
      },
      change2(val){
        if(val == true){
          this.boo2 = true
        }else if(val == false){
          this.boo2 = false
        }
      },
      changes(val){
        this.a = val
        if(val == true){
          this.zios = true
        }else if(val == false && this.b == false){
          this.zios = false
        }
      },
      changes1(val){
        this.c = val
        if(val == true){
          this.zios1 = true
        }else if(val == false && this.d == false){
          this.zios1 = false
        }
      },
      changes2(val){
        this.e = val
        if(val == true){
          this.zios2 = true
        }else if(val == false && this.f == false){
          this.zios2 = false
        }
      },
      changea(val){
        this.b = val
        if(val == true){
          this.zios = true
        }else if(val == false && this.a == false){
          this.zios = false
        }
      },
      changesb(val){
        this.d = val
        if(val == true){
          this.zios1 = true
        }else if(val == false && this.c == false){
          this.zios1 = false
        }
      },
      changesc(val){
        this.f = val
        if(val == true){
          this.zios2 = true
        }else if(val == false && this.e == false){
          this.zios2 = false
        }
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加供应商管理";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.open = true
        const sqeId = row.sqeId || this.ids
        getSupplierMgmt(sqeId).then(response => {
          this.form = response.data;
          this.form.vendorFolderPermissions = this.form.vendorFolderPermissions.split(",");
          this.form.ictUpFolderPermissions = this.form.ictUpFolderPermissions.split(",");
          this.form.auditorFolderPermissions = this.form.auditorFolderPermissions.split(",");
          this.open = true;
          this.title = "修改供应商管理";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            console.log(this.form)
            this.form.vendorFolderPermissions = this.form.vendorFolderPermissions.join(",");
            this.form.ictUpFolderPermissions = this.form.ictUpFolderPermissions.join(",");
            this.form.auditorFolderPermissions = this.form.auditorFolderPermissions.join(",");
            if (this.form.sqeId != null) {
              updateSupplierMgmt(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addSupplierMgmt(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const sqeIds = row.sqeId || this.ids;
        this.$modal.confirm('是否确认删除供应商管理编号为"' + sqeIds + '"的数据项？').then(function() {
          return delSupplierMgmt(sqeIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        const queryParams = this.queryParams;
        this.$modal.confirm('是否确认导出所有供应商管理数据项？').then(() => {
          this.exportLoading = true;
          return exportSupplierMgmt(queryParams);
        }).then(response => {
          this.$download.name(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
      }
    }
  };
</script>
